package com.hspedu.springcloud.controller;

import com.hspedu.springcloud.entity.Member;
import com.hspedu.springcloud.entity.Result;
import com.hspedu.springcloud.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by Gening on 13/6/2025
 */
@Slf4j
@RestController
public class MemberController {
    @Resource
    private MemberService memberService;

    @PostMapping("/member/save")
    public Result save(@RequestBody Member member){
        int affect=memberService.save(member);
        if(affect>0){
        return Result.success("add success",affect);

    }else {
          return Result.error("401","添加失败");
        }
    }

    @GetMapping("/member/get/{id}")
    public Result getMemberById(@PathVariable ("id")Long id){
        Member member = memberService.queryById(id);
        if(member!=null){
            return Result.success("查询成功",member);
        }else {
            return Result.error("401","添加id不存在");
        }

    }
}
